class SideboxController < ApplicationController
  def show
    @sideboxes = Sidebox.find(:all)
    respond_to do |format|
        format.html 
    end  
  end
  
  def new
    @sidebox = Sidebox.new
  end
  
  def edit
    @sidebox = Sidebox.find(params[:id])
  end
  
  def create
    @sidebox = Sidebox.new(params[:sidebox])
       
    @page = Page.new
    @page.pageName = @sidebox.title
    @page.categoryNameUrl = "index"
    @page.pageNameUrl = Page.cleanUrl(@page.pageName)
    @page.hasFlash = 1
    @page.hasAutoTitle = 1
    @page.hasBreadcrumb = 0
    @page.HTMLContent = "New Page."
    
    @sidebox.url = @page.getUrl()

    respond_to do |format|
      if @page.save 
        if @sidebox.save
          flash[:notice] = 'Page was successfully created.'
          format.html { redirect_to(@page.getUrl) }
          format.xml  { render :xml => @page, :status => :created, :location => @page }
        end
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @sidebox.errors, :status => :unprocessable_entity }
      end
    end
  end
  
    def update
    @sidebox = Sidebox.find(params[:id])

    respond_to do |format|
      if @sidebox.update_attributes(params[:sidebox])
        flash[:notice] = 'Page was successfully updated.'
        format.html { redirect_to(@sidebox.url) }
      end
    end
  end
  
  def destroy
    @sidebox = Sidebox.find(params[:id])
    @sidebox.destroy

    respond_to do |format|
      flash[:notice] = 'Sidebox was successfully deleted.'
      format.html { redirect_to("/index.html") }
      format.xml  { head :ok }
    end
  end
end
